package com.damuzee.weixin.config.action;

import javax.annotation.Resource;

import org.mybatis.sql.condition.Criteria;
import org.mybatis.sql.page.Page;
import org.mybatis.sql.page.Pagination;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.damuzee.core.action.BaseAction;
import com.damuzee.core.domain.JsonResult;
import com.damuzee.weixin.config.domain.AccoutBind;
import com.damuzee.weixin.config.persistence.AccoutBindMapper;
import com.damuzee.weixin.config.service.IAccoutBindService;

@Controller
public class AccoutBindAction extends BaseAction{
	
	@RequestMapping(value="/actbind/add.do")
	public String add(){
		return  "/actbind/add" ;
	}
	
	@RequestMapping(value="/actbind/list.do")
	public String list(ModelMap model){
		Page<AccoutBind> page = new Page<AccoutBind>();
		page = accoutBindMapper.selectPageByWhere(page, new AccoutBind());
		model.addAttribute("page", page.getPage());
		return  "/actbind/list" ;
	}
	
	@RequestMapping(value="/actbind/list.do",method = RequestMethod.POST)
	@ResponseBody
	public Pagination<AccoutBind> list(Integer pageNum, Integer totalCount ,Integer pageSize ,
			String orderby, String order , ModelMap map){
		Page<AccoutBind> page = new Page<AccoutBind>();
		page.setCurrentPage(pageNum);
		if(totalCount != null){
			page.setTotal(totalCount);
		}
		page.setSize(pageSize);
		Criteria cri = new Criteria(AccoutBind.class);
		
		if(orderby!= null && order != null ){
			cri.order(orderby, order);
		}
		
		page = accoutBindMapper.selectPageByCriteria(page, cri);
		return  page.getPage();
	}
	
	@RequestMapping(value="/actbind/save.do")
	@ResponseBody
	public JsonResult save(AccoutBind accoutBind){
		accoutBindService.saveAccoutBind(accoutBind);
		jsonResult.setMsgType(JsonResult.MSGTYLE_ERROR);
		return jsonResult;
	}
	
	@Resource
	private IAccoutBindService accoutBindService ;
	
	@Resource
	private AccoutBindMapper accoutBindMapper ;
	
}
